1. Field of the Invention
The present invention is related generally to a data processing system and in particular to a method and apparatus for compiling program code. More particularly, the present invention is directed to a computer implemented method, apparatus, and computer usable program code for flow control sensitive refinement of address taken variables.
2. Description of the Related Art
A compiler is a software component in a computer that translates a computer program written in one language into a different computer language. Typically, a compiler translates or compiles a high level language program into machine code for a target computer. An optimizing compiler is a software component for tuning or optimizing compiled code to improve some aspect of the compiled code so that the code will execute more rapidly or more efficiently so that the executable code will consume fewer processor resources.
In program code, when an address of a variable is taken, the content of the address may be overwritten during the execution of the code. Therefore, when program code is compiled and optimized, address taken variables should be taken into account when determining which code blocks to optimize and which code blocks should not be optimized or altered to improve execution performance. Current solutions for optimizing address taken variables include disambiguating the indirect references from the direct references to refine the alias set of address taken variable.
For example, in one solution, compilers analyze how address taken global variables and/or address taken local variables are being accessed in a program to refine the address taken variables. However, these current optimization techniques for refining address taken information do not take the control flow of a program into consideration.
The control flow of a program is the order in which statements in the program are executed. Typically, statements are executed in the order in which the statements are written in the program, in a top down fashion. However, control flow statements, such as loops and conditional statements, may alter the control flow, such that statements in the program code are no longer executed in order. Currently available techniques for optimizing code are either flow-insensitive or require inter-procedural analysis, which is very costly in terms of compile time.
Therefore, compilers frequently treat address taken variables conservatively. These compilers generally store a value for a given address taken variable to memory for all the references to the given address taken variable that occur in the program code before the address of the given address taken variable is actually taken. Thus, if a variable is referenced in an “if” path and the variable's address is taken on the “else” path, current compilers will store its value to memory on both the “if” path and the “else” path, even though the address of the variable is only taken on the “else” path. This type of flow insensitive aliasing and the techniques that address them can be expensive to implement both in terms of compile time and compiler resources required to implement them.